<template>
  <div>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input v-model="query" placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search" />
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="orderList" border style="width: 100%">
        <el-table-column type="index" label="序号" width="80" />
        <el-table-column prop="uname" label="订单用户" />
        <el-table-column prop="price" label="金额" />
        <el-table-column prop="pay_status" label="是否支付">
          <template v-slot="scope">
            <el-tag v-if="scope.row.pay_status == 0" type="danger">未支付</el-tag>
            <el-tag v-else>已支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发件">
          <template v-slot="scope">
            <el-tag v-if="scope.row.pay_status == 0" type="danger">未发件</el-tag>
            <el-tag v-else>已发件</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-slot="scope" label="操作">
          <el-button type="primary" size="small" icon="el-icon-s-tools" @click="handleClick(scope.row)">地址</el-button>
          <el-button type="success" size="small" icon="el-icon-location" @click="handleShowExpress(scope.row)">物流</el-button>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog title="物流信息" :visible.sync="expressVisible" width="30%">
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.update_time"
        >
          {{ activity.content }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="expressVisible = false">取 消</el-button>
        <el-button type="primary" @click="expressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { orderList, expressList } from '@/api/order'
export default {
  name: 'OrderList',
  data() {
    return {
      query: '',
      orderList: [],
      expressVisible: false,
      reverse: true,
      activities: []
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    // 获取订单列表数据
    async getOrderList() {
      const res = await orderList()
      if (res.status !== 200) return this.$message.error('获取订单列表失败！')
      this.orderList = res.data
    },
    handleClick() {

    },
    // 展示物流信息的弹框
    async handleShowExpress(row) {
      this.expressVisible = true
      const res = await expressList(row.id)
      if (res.status !== 200) return this.$message.error('获取物流信息失败！')
      this.activities = res.data
    }
  }

}
</script>

<style scoped>
.el-table {
  margin-top: 20px;
}
</style>
